<template>
  <div>
    <!--导航栏-->
    <van-nav-bar
        title="新增地址"
        left-text="返回"
        left-arrow
        :fixed=true
        :border=true
        @click-left="goBack"
    />
      <van-address-edit
              :area-list="areaList"
              show-postal
              show-set-default
              :area-columns-placeholder="['请选择', '请选择', '请选择']"
              @save="onSave"
              style="margin-top: 3rem"
      />

  </div>

</template>

<script>
import {Toast} from "vant";
import areaList from '../../../../config/area';
import {addUserAddress} from "@/api/api";
 export default {
  name: "AddAddress",
  data() {
    return {
      areaList,
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    // 保存用户信息
    onSave(content) {
      const obj = {
        name:content.name,
        phone:content.tel,
        areaCode:content.areaCode,
        region:content.country+content.province+content.city+content.county,
        detailedAddress:content.addressDetail,
        zipCode:content.postalCode,
        isDefault:content.isDefault ? "1" : "0"//数据库该项设置为0，1，如不需修改可删除该行
      };
      console.log(obj)
      addUserAddress(obj).then(
         ()=>{
           Toast("添加成功");
           this.$router.back();
         }
      )
    },
  },

}
</script>
<style scoped>

</style>